package datasource;

import datasource.config.C3P0Config;
import jdbc.main.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/14.
 */
public class UserDao {
    public int pageSize=3;
public List<User> findPage(int page) throws SQLException {
    Connection con=C3P0Config.geyConnection();
     List<User> list=new ArrayList<>();

        User user=new User();
        String sql="select * from user order by id desc limit ?,?";
        PreparedStatement ps=con.prepareStatement(sql);
        ps.setInt(1,(page-1)*pageSize);
        ps.setInt(2,pageSize);
        ResultSet set=ps.executeQuery();
        while (set.next())
        {
            user.getId(set.getInt(1));
            user.getUnname(set.getString(2));
            user.getPhone(set.getString(3));
            list.add(user);
        }
        return list;
    }
}
